/** \file PriceChannel_t.cc 
 * Test definitions for the PriceChannel function.
 *
 * (C) Copyright by Semih Cemiloglu
 * All rights reserved, see COPYRIGHT file for details.
 *
 * $Id: PriceChannel_t.cc 110 2006-06-19 03:38:33Z semihc $
 *
 *
 */


#include "PriceChannel.hpp"
#include <list>
#include <vector>
#include "Stock.hpp"
#include "SecurityAdaptor.hpp"
#include "TestHarness.hh"

using namespace std;
using namespace TC;


namespace {

  const unsigned DataSize = 27;

  const double data_hi[DataSize] = {
    2.8907, 2.9063, 2.8750, 2.8543, 2.9740, 3.0730, 3.1563,
    3.1617, 3.1147, 3.1617, 3.1877, 3.2293, 3.1667, 3.1823,
    3.1147, 3.1303, 3.1093, 3.0833, 3.1617, 3.2187, 3.1927,
    3.1980, 3.1563, 3.2033, 3.2500, 3.2293, 3.1823 };

  const double data_lo[DataSize] = {
    2.8437, 2.8543, 2.8333, 2.8127, 2.8647, 2.9793, 3.0937,
    3.0677, 3.0520, 3.0520, 3.0573, 3.1353, 3.1303, 3.1200,
    3.0470, 3.0520, 3.0417, 3.0210, 3.1250, 3.1617, 3.1563,
    3.1563, 3.0833, 3.1093, 3.2033, 3.1927, 3.1353 };


  const double expect_hi[DataSize] = {
    0, 0, 0, 0, 0,
    2.9740, 3.0730, 3.1563, 3.1617, 3.1617, 3.1617, 3.1877,
    3.2293, 3.2293, 3.2293, 3.2293, 3.2293, 3.1823, 3.1823,
    3.1617, 3.2187, 3.2187, 3.2187, 3.2187, 3.2187, 3.2500,
    3.2500 };

  const double expect_lo[DataSize] = {
    0, 0, 0, 0, 0,
    2.8127, 2.8127, 2.8127, 2.8127, 2.8647, 2.9793, 3.0520,
    3.0520, 3.0520, 3.0520, 3.0470, 3.0470, 3.0417, 3.0210,
    3.0210, 3.0210, 3.0210, 3.0210, 3.0833, 3.0833, 3.0833,
    3.0833 };



}


TEST(PriceChannelTest, Base)
{
     StockDef s;
     list<StockDef> stocks;
     vector<TAfp_t> pclo, pchi;
     unsigned i;

     
     for(i=0; i<DataSize; ++i) {
       s.setHi(static_cast<StockDef::Price_t>(data_hi[i]));
       s.setLo(static_cast<StockDef::Price_t>(data_lo[i]));
       stocks.push_back(s);
     }

     // Price Channel of a given price data
     PriceChannel(stocks.begin(), stocks.end(),
		  back_inserter(pclo),
		  back_inserter(pchi),
		  5, // 5  period
		  SecurityAdaptor<StockDef>());

     TC_TEST(pclo.size()==DataSize);
     TC_TEST(pchi.size()==DataSize);

     PrintElements(pclo, "PriceChannel-low");
     PrintElements(pchi, "PriceChannel-high");

     for(i=0; i<DataSize; ++i)
       if(expect_lo[i] > 0)
         TC_TESTFP(expect_lo[i], pclo[i]);

     for(i=0; i<DataSize; ++i)
       if(expect_hi[i] > 0)
         TC_TESTFP(expect_hi[i], pchi[i]);

}

  



